package org.shoukaiseki.common.utils

import org.apache.commons.lang3.BooleanUtils

object BooleanUtils {

    const val TRUE = "true"
    const val ONE = "1"
    const val Y = "y"
    const val YES = "yes"
    const val ON = "on"
    @JvmStatic
    fun isTrue(obj: Any?): Boolean {
        if (obj == null) {
            return false
        }
        if (obj is Boolean) {
            BooleanUtils.isTrue(obj as Boolean?)
        }
        if (obj is Number) {
            return obj.toInt() == 1
        }
        return if (obj is String) {
            StringUtils.equalsAnyIgnoreCase(obj.toString(), TRUE, Y, ONE, YES, ON)
        } else StringUtils.equalsAnyIgnoreCase(obj.toString(), TRUE, Y, ONE, YES, ON)
    }

    @JvmStatic
    fun isFalse(obj: Any?): Boolean {
        return !isTrue(obj)
    }

    @JvmStatic
    fun allTrue(vararg arrs: Boolean): Boolean {
       return !anyFalse(*arrs)
    }

    @JvmStatic
    fun anyTrue(vararg arrs: Boolean): Boolean {
        return !allFalse(*arrs)
    }

    @JvmStatic
    fun allFalse(vararg arrs: Boolean): Boolean {
        for (arr in arrs) {
            if(arr){
                return false
            }
        }
        return true
    }


    @JvmStatic
    fun anyFalse(vararg arrs: Boolean): Boolean {
        for (arr in arrs) {
            if(!arr){
                return true
            }
        }
        return false
    }
}